﻿import QtQuick 2.12
import QtQuick.Window 2.12
import TaoQuick 1.0
import Top 1.0

Item {
    CusButton_ImageBackground {
        width: 45
        height: 45
        btnImgUr: "qrc:/Image/back.png"
        onClicked:  {
            tcpClient.displayIndex=0
        }
    }

    Column {
        anchors.centerIn: parent
        spacing: 20
        Row {
            anchors.horizontalCenter: parent.horizontalCenter
            CusLabel {
                text: "账号"
                width: 60
                anchors.verticalCenter: parent.verticalCenter
            }

            CusTextField {
                id: accountId
                width: 200
                height: 30
            }
            //这样可以保持前面的输入框不动
            Item {
                width: 1
                height: 30
                CusLabel {
                    anchors.verticalCenter: parent.verticalCenter
                    text: {
                        if(GlobalManager.tcpClientManager.replyCode == TcpClientManager.RegisterAccountSucceeded) {
                            return "注册成功"
                        }else if( GlobalManager.tcpClientManager.replyCode == TcpClientManager.RegisterAccountExist){
                            return "注册失败，账号已经存在"
                        }else {
                            return ""
                        }
                    }

                    color: "red"
                    font.pixelSize: 14
                    leftPadding: 10
                    width: 300
                }
            }
        }
        Row {
            anchors.horizontalCenter: parent.horizontalCenter
            CusLabel {
                text: "密码"
                width: 59
                anchors.verticalCenter: parent.verticalCenter
            }

            CusTextField {
                id: passwordId
                width: 200
                height: 30
            }
        }
        Row {
            spacing: 20
            anchors.horizontalCenter: parent.horizontalCenter
            CusButton {
                width: 80
                height: 40
                text: "注册账号"
                enabled: passwordId.text != "" && accountId.text != ""
                onClicked: {
                    GlobalManager.tcpClientManager.registerAccount(accountId.text, passwordId.text)
                }
            }
        }
    }
}
